//
//  DrawInContextViewController.m
//  CoreAnimation
//
//  Created by 张国文 on 16/10/13.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "DrawInContextViewController.h"
#import "DrawInContextView.h"

@interface DrawInContextViewController ()

@property (nonatomic, strong) DrawInContextView *myView;

@end

@implementation DrawInContextViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.myView = [[DrawInContextView alloc] initWithFrame:CGRectMake(100, 200, 200, 200)];
  
    self.myView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:_myView];
    
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    button1.frame = CGRectMake(50, 500, 200, 30);
    button1.backgroundColor = [UIColor cyanColor];
    [button1 setTitle:@"重绘" forState:UIControlStateNormal];
    [button1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(button1:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button1];
}

- (void)button1:(UIButton *)button
{
    [self.myView setNeedsDisplay]; // 这个会走drawRect，但是在调用drawRect方法之前会走drawInContext方法
 //   [self.myView.layer setNeedsDisplay]; // 这个方法有同样的效果,在调用drawRect方法之前会走drawInContext方法
}


@end
